﻿using System;
using System.Collections.Generic;
using System.Text;
using ebay.ebayApi;
using eBay.Service.Core.Soap;
using ebay.Dal;

namespace ebay.BLL
{
    public class Contidion
    {
        public List<ebay.Model.Condition> GetConditionList()
        {
            EbayAccount account = new EbayAccount();

            string token = account.GetToken();
            if (string.IsNullOrEmpty(token))
            {
                throw new Exception("数据库中还没有账户信息");
            }
            ebayCallsApi apicall = new ebayCallsApi(token);

            CategoryFeatureTypeCollection gftc = apicall.GetCondition();
            List<ebay.Model.Condition> list = new List<ebay.Model.Condition>();
            if (gftc.Count > 0)
            {
                CategoryFeatureType cft = gftc[0];
                if (cft.ConditionEnabled == ConditionEnabledCodeType.Enabled ||
            cft.ConditionEnabled == ConditionEnabledCodeType.Required)
                {
                    ConditionTypeCollection cvt = cft.ConditionValues.Condition;
                    foreach (ConditionType s in cvt)
                    {
                        ebay.Model.Condition m = new ebay.Model.Condition();
                        m.ConditionId = s.ID;
                        m.ConditionName = s.DisplayName;
                        list.Add(m);
                    }
                }
            }
            return list;
        }
    }
}
